package com.giaothong.db;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * SharedPreference adapter for set/get data to SharedPreference
 */
public class SharePreferenceAdapter {

	public static final String DEFAULT_BLANK = "";

	private static SharePreferenceAdapter instance = new SharePreferenceAdapter();
	private SharedPreferences sharedPreferences;

	private SharePreferenceAdapter() {
	}

	public static SharePreferenceAdapter getInstance() {
		return instance;
	}

	public void init(Context context) {
		if (sharedPreferences == null) {
			sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		}
	}

	public void save(String key, String value) {
		sharedPreferences.edit().putString(key, value).commit();
	}

	public String get(String key, String _default) {
		return sharedPreferences.getString(key, _default);
	}

	public void save(String key, boolean value) {
		sharedPreferences.edit().putBoolean(key, value).commit();
	}

	public boolean get(String key, boolean _default) {
		return sharedPreferences.getBoolean(key, _default);
	}

}
